#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

const int N=2e5+10;

typedef long long LL;

int m,p,x,last;
char op[2];

struct node
{
    int l,r;
    int v;
}tree[N*4];

void pushup(int u)
{
    tree[u].v=max(tree[u*2].v,tree[u*2+1].v);
}

void bulid(int u,int l,int r)
{
    tree[u].l=l;
    tree[u].r=r;
    if(l==r) return;
    int mid=(l+r)/2;
    bulid(u*2,l,mid),bulid(u*2+1,mid+1,r);
}

int query(int u,int l,int r)
{
    if(tree[u].l>=l && tree[u].r<=r) return tree[u].v;
    int mid=(tree[u].l+tree[u].r)/2;
    int v=0;
    if(l<=mid) v=query(u*2,l,r);
    if(r>mid) v=max(v,query(u*2+1,l,r));
    return v;
}

void modify(int u,int x,int v)
{
    if(tree[u].l==x && tree[u].r==x) tree[u].v=v;
    else
    {
        int mid=(tree[u].l+tree[u].r)/2;
        if(x<=mid) modify(u*2,x,v);
        else modify(u*2+1,x,v);
        pushup(u);
    }
}

int main()
{
    int n=0,last=0;
    cin>>m>>p;
    bulid(1,1,m);
    while(m--)
    {
        scanf("%s%d",op,&x);
        if(*op=='Q')
        {
            last=query(1,n-x+1,n);
            cout<<last<<endl;
        }
        else
        {
            modify(1,n+1,((LL)last+x)%p);
            n++;
        }
    }
    return 0;
}
